import {
	createApp
} from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';

import installAxios from './plugins/axios';
import '@/assets/styles/reset.css';
import '@/assets/styles/common.scss';
import ElementPlus from 'element-plus';
import 'element-plus/lib/theme-chalk/index.css';

//高亮显示
// import hljs from 'highlight.js'

// 公共组件
import BasicOpt from '@/components/common/basic-opt.vue'
import ResetSearch from '@/components/common/reset-search.vue'
import CompomentDrawer from '@/components/common/compoment-drawer.vue'
import PageComponent from '@/components/common/page-component.vue'
import SubmitReset from '@/components/common/submit-reset.vue'
import DeleteData from '@/components/common/delete-data.vue'

router.beforeEach((to, from, next) => {
	document.title = `${to.meta.title} - 图巴诺后台系统`;
	const token = localStorage.getItem('token');
	if (!token) {
		if ((to.path == '/version') || (to.path == '/device-opertion') || (to.path == '/room')) {
			next({
				path: '/login'
			})
		}
		if (to.matched.length > 0 && !to.matched.some(record => record.meta.requiresAuth)) {
			next()
		} else {
			next({
				path: '/login'
			})
		}
	} else {
		if (store.state.permission.permissionList == null) {
			store.dispatch('permission/FETCH_PERMISSION').then(() => {
				next({
					path: to.path
				})
			})
		} else {
			if (to.path !== '/login') {
				next()
			} else {
				next(from.fullPath)
			}
		}
	}
})



const app = createApp(App);
app.use(router);
app.use(store);
app.use(ElementPlus);
app.use(installAxios);
app.component('BasicOpt', BasicOpt);
app.component('ResetSearch', ResetSearch);
app.component('CompomentDrawer', CompomentDrawer);
app.component('PageComponent', PageComponent);
app.component('SubmitReset', SubmitReset);
app.component('DeleteData', DeleteData);
app.mount('#app');
